<?php
    defined('M2_MICRO') or die('Direct Access to this location is not allowed.');

    /**
      * @desc restful controller
      * @package M2 Micro Framework
      * @author Alexander Chaika
      */

    $request = substr($_SERVER['REQUEST_URI'], 1);
    $result = strstr($request, "?");
    
    if ($result) {
        $route = explode('/', substr($request, 0, strlen($request) - strlen($result)));
    } else {
        $route = explode('/', $request);
    }

    if (count($route) > 0 && !empty($route[0])) {
        $_REQUEST['module'] = $route[0];
    }

    if (count($route) > 1 && !empty($route[1])) {
        $_REQUEST['action'] = $route[1];
    }
    
    if (count($route) > 2 && !empty($route[2])) {
        $_REQUEST['task'] = $route[2];
    }
?>
